package com.mlnx.work.pojo.vo;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.mlnx.work.entity.TaskArrange;
import com.mlnx.work.entity.TaskOverdue;
import com.mlnx.work.enums.ProjectStatusEnum;
import com.mlnx.work.utils.DateUtil;
import com.mlnx.work.utils.TagUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiModel("任务详情返回参数类")
public class TaskDetailVO {

    @ApiModelProperty("任务ID")
    private Integer taskId;

    @ApiModelProperty("任务名称")
    private String taskName;

    @ApiModelProperty("任务描述")
    private String description;

    @ApiModelProperty("任务创建时间")
    private Long createTime;

    @ApiModelProperty("最初计划开始时间")
    private Long originStartTime;

    @ApiModelProperty("实际开始时间")
    private Long startTime;

    @ApiModelProperty("最初计划结束时间")
    private Long originEndTime;

    @ApiModelProperty(value = "任务实际完成时间")
    private Long completedTime;

    @ApiModelProperty("逾期计划时间")
    private Long overdueTime;

    @ApiModelProperty("逾期比")
    private Float overdueRate;

    @ApiModelProperty("逾期次数")
    private Integer overdueTimes;

    @ApiModelProperty(value = "成果交付")
    private String achievement;

    @ApiModelProperty(value = "风险项")
    private String risk;

    @ApiModelProperty(value = "标签")
    private String tags;

    @ApiModelProperty(value = "里程碑")
    private Boolean milepost;

    @ApiModelProperty(value = "工时")
    private Integer workHour;

    @EnumValue
    @ApiModelProperty(value = "任务状态，TaskStatusEnum枚举")
    private ProjectStatusEnum status;

    @ApiModelProperty("负责人")
    private String manager;

    @ApiModelProperty("参与成员")
    List<String> members;

    @ApiModelProperty("子任务列表")
    List<ChildTaskListVO> childTaskList;

    @ApiModelProperty("任务逾期")
    List<TaskOverdueVO> taskOverdues;

    @ApiModelProperty("任务周计划")
    List<TaskArrange> taskArranges;

    public Long getOverdueTime() {
        if (taskOverdues == null || taskOverdues.size() <= 0)
            return null;

        return taskOverdues.get(taskOverdues.size() - 1).getOverdueTime();
    }

    public Float getOverdueRate() {
        if (taskOverdues == null || taskOverdues.size() <= 0)
            return 0f;

        overdueTime = taskOverdues.get(taskOverdues.size() - 1).getOverdueTime();

        float f1 = DateUtil.dayBetween(overdueTime, originStartTime) + 1;
        float f2 = DateUtil.dayBetween(originEndTime, originStartTime) + 1;
        return f1 / f2;
    }

    public Integer getOverdueTimes() {
        if (taskOverdues == null || taskOverdues.size() <= 0)
            return null;

        return taskOverdues.size();
    }

    public String getStatus() {
        if (ProjectStatusEnum.ING.equals(status))
            if (DateUtil.dateCompare(originEndTime, System.currentTimeMillis()) < 0)
                status = ProjectStatusEnum.OVERDUE;
            else if (!risk.trim().isEmpty())
                status = ProjectStatusEnum.RISK;

        return status.getStatus();
    }

    public List<String> getTags() {
        return TagUtil.getTags(tags);
    }
}
